package com.example.webgobang.mapper;

import com.example.webgobang.model.domin.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    @Insert("insert into user (username, password, score) values (#{username}, #{password}, 1000)")
    void insertUser(User user);

    @Select("select * from user where username = #{username}")
    User selectByName(String username);

    @Select("select * from user where id = #{userId}")
    User selectById(Integer userId);

    @Update("update user set score = score + 30, " +
            "total_count = total_count + 1, " +
            "win_count = win_count + 1 " +
            "where id = #{userId}")
    void updateWinUser(int userId);

    @Update("update user set score = score - 30, " +
            "total_count = total_count + 1 " +
            "where id = #{userId}")
    void updateLoseUser(int userId);
}
